package cn.meng.base.handler;

import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import cn.meng.base.vo.ExceptionMessageVo;
import cn.meng.base.vo.BusinessException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * 拦截全局所有请求中的Exception级别的异常
 * @author 万梦辉
 */
@RestControllerAdvice
public class BussinessExceptionHandler {

    /**
     * 获取日志
     */
    private final Logger log = LoggerFactory.getLogger(this.getClass());

    @ExceptionHandler(BusinessException.class)
    public JSONObject handlerException(BusinessException e) {
        ExceptionMessageVo exception = new ExceptionMessageVo(e);
        JSONObject json = JSONUtil.parseObj(exception, false,true);
        return json;
    }

}
